package top.abilities.util.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.abilities.util.domain.WeekData;

import top.abilities.util.param.DayCompare;
import top.abilities.util.util.validate.ValidateUtils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * 日期工具类
 */
public class DateUtils extends org.apache.commons.lang.time.DateUtils {

    public static final String TIME_WITH_MINUTE_PATTERN = "HH:mm";

    public static final long DAY_MILLI = 24 * 60 * 60 * 1000; // 一天的MilliSecond

    public final static int LEFT_OPEN_RIGHT_OPEN = 1;
    public final static int LEFT_CLOSE_RIGHT_OPEN = 2;
    public final static int LEFT_OPEN_RIGHT_CLOSE = 3;
    public final static int LEFT_CLOSE_RIGHT_CLOSE = 4;
    /**
     * 比较日期的模式 --只比较日期，不比较时间
     */
    public final static int COMP_MODEL_DATE = 1;
    /**
     * 比较日期的模式 --只比较时间，不比较日期
     */
    public final static int COMP_MODEL_TIME = 2;
    /**
     * 比较日期的模式 --比较日期，也比较时间
     */
    public final static int COMP_MODEL_DATETIME = 3;

    private static Logger logger = LoggerFactory.getLogger(DateUtils.class);

    /**
     * 要用到的DATE Format的定义
     */
    private static SimpleDateFormat simpleDateFormat;
    public static String DATE_FORMAT_DATEONLY = "yyyy-MM-dd"; // 年/月/日
    public static String DATE_FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss"; // 年/月/日
    public static SimpleDateFormat sdfDateTime = new SimpleDateFormat(DateUtils.DATE_FORMAT_DATETIME);
    // Global SimpleDateFormat object
    public static SimpleDateFormat sdfDateOnly = new SimpleDateFormat(DateUtils.DATE_FORMAT_DATEONLY);
    public static final SimpleDateFormat SHORTDATEFORMAT = new SimpleDateFormat("yyyyMMdd");
    public static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    public static final SimpleDateFormat LONG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static final SimpleDateFormat HMS_FORMAT = new SimpleDateFormat("HH:mm:ss");
    public static final SimpleDateFormat formatTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
    private final static SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");


    /**
     * 根据日期格式字符串解析日期字符串
     *
     * @param str           日期字符串
     * @param parsePatterns 日期格式字符串
     * @return 解析后日期
     * @throws ParseException
     */
    public static Date parseDate(String str, String parsePatterns) throws ParseException {
        return parseDate(str, new String[]{parsePatterns});
    }

    /**
     * 根据单位字段比较两个日期
     *
     * @param date      日期1
     * @param otherDate 日期2
     * @param withUnit  单位字段，从Calendar field取值
     * @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
     */
    public static int compareDate(Date date, Date otherDate, int withUnit) {
        Calendar dateCal = Calendar.getInstance();
        dateCal.setTime(date);
        Calendar otherDateCal = Calendar.getInstance();
        otherDateCal.setTime(otherDate);

        switch (withUnit) {
            case Calendar.YEAR:
                dateCal.clear(Calendar.MONTH);
                otherDateCal.clear(Calendar.MONTH);
            case Calendar.MONTH:
                dateCal.set(Calendar.DATE, 1);
                otherDateCal.set(Calendar.DATE, 1);
            case Calendar.DATE:
                dateCal.set(Calendar.HOUR_OF_DAY, 0);
                otherDateCal.set(Calendar.HOUR_OF_DAY, 0);
            case Calendar.HOUR:
                dateCal.clear(Calendar.MINUTE);
                otherDateCal.clear(Calendar.MINUTE);
            case Calendar.MINUTE:
                dateCal.clear(Calendar.SECOND);
                otherDateCal.clear(Calendar.SECOND);
            case Calendar.SECOND:
                dateCal.clear(Calendar.MILLISECOND);
                otherDateCal.clear(Calendar.MILLISECOND);
            case Calendar.MILLISECOND:
                break;
            default:
                throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法！！");
        }
        return dateCal.compareTo(otherDateCal);
    }

    /**
     * 根据单位字段比较两个时间
     *
     * @param date      时间1
     * @param otherDate 时间2
     * @param withUnit  单位字段，从Calendar field取值
     * @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
     */
    public static int compareTime(Date date, Date otherDate, int withUnit) {
        Calendar dateCal = Calendar.getInstance();
        dateCal.setTime(date);
        Calendar otherDateCal = Calendar.getInstance();
        otherDateCal.setTime(otherDate);

        dateCal.clear(Calendar.YEAR);
        dateCal.clear(Calendar.MONTH);
        dateCal.set(Calendar.DATE, 1);
        otherDateCal.clear(Calendar.YEAR);
        otherDateCal.clear(Calendar.MONTH);
        otherDateCal.set(Calendar.DATE, 1);
        switch (withUnit) {
            case Calendar.HOUR:
                dateCal.clear(Calendar.MINUTE);
                otherDateCal.clear(Calendar.MINUTE);
            case Calendar.MINUTE:
                dateCal.clear(Calendar.SECOND);
                otherDateCal.clear(Calendar.SECOND);
            case Calendar.SECOND:
                dateCal.clear(Calendar.MILLISECOND);
                otherDateCal.clear(Calendar.MILLISECOND);
            case Calendar.MILLISECOND:
                break;
            default:
                throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法！！");
        }
        return dateCal.compareTo(otherDateCal);
    }

    /**
     * 获得当前的日期毫秒
     *
     * @return
     */
    public static long nowTimeMillis() {
        return System.currentTimeMillis();
    }

    /**
     * 获得当前的时间戳
     *
     * @return
     */
    public static Timestamp nowTimeStamp() {
        return new Timestamp(nowTimeMillis());
    }

    /**
     * yyyyMMdd 当前日期
     */
    public static String getReqDate() {
        return SHORTDATEFORMAT.format(new Date());
    }

    /**
     * yyyy-MM-dd 当前日期
     */
    public static String getReqDates() {
        return SHORT_DATE_FORMAT.format(new Date());
    }

    /**
     * yyyy-MM-dd 传入日期
     *
     * @param date
     * @return
     */
    public static String getReqDate(Date date) {
        return SHORT_DATE_FORMAT.format(date);
    }

    /**
     * yyyyMMdd 传入日期
     *
     * @param date
     * @return
     */
    public static String getReqDateyyyyMMdd(Date date) {
        return SHORTDATEFORMAT.format(date);
    }

    /**
     * yyyy-MM-dd 传入的时间戳
     *
     * @param tmp
     * @return
     */
    public static String TimestampToDateStr(Timestamp tmp) {
        return SHORT_DATE_FORMAT.format(tmp);
    }

    /**
     * HH:mm:ss 当前时间
     *
     * @return
     */
    public static String getReqTime() {
        return HMS_FORMAT.format(new Date());
    }

    /**
     * 得到时间戳格式字串
     *
     * @param date
     * @return
     */
    public static String getTimeStampStr(Date date) {
        return LONG_DATE_FORMAT.format(date);
    }

    /**
     * 得到长日期格式字串
     *
     * @return
     */
    public static String getLongDateStr() {
        return LONG_DATE_FORMAT.format(new Date());
    }

    public static String getLongDateStr(Timestamp time) {
        return LONG_DATE_FORMAT.format(time);
    }

    /**
     * 得到短日期格式字串
     *
     * @param date
     * @return
     */
    public static String getShortDateStr(Date date) {
        return SHORT_DATE_FORMAT.format(date);
    }

    public static String getShortDateStr() {
        return SHORT_DATE_FORMAT.format(new Date());
    }

    /**
     * 计算 second 秒后的时间
     *
     * @param date
     * @param second
     * @return
     */
    public static Date addSecond(Date date, int second) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.SECOND, second);
        return calendar.getTime();
    }

    /**
     * 计算 minute 分钟后的时间
     *
     * @param date
     * @param minute
     * @return
     */
    public static Date addMinute(Date date, int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minute);
        return calendar.getTime();
    }

    /**
     * 计算 hour 小时后的时间
     *
     * @param date
     * @param hour
     * @return
     */
    public static Date addHour(Date date, int hour) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR, hour);
        return calendar.getTime();
    }

    /**
     * 得到day的起始时间点。
     *
     * @param date
     * @return
     */
    public static Date getDayStart(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 得到day的终止时间点.
     *
     * @param date
     * @return
     */
    public static Date getDayEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.MILLISECOND, -1);
        return calendar.getTime();
    }

    /**
     * 计算 day 天后的时间
     *
     * @param date
     * @param day
     * @return
     */
    public static Date addDay(Date date, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, day);
        return calendar.getTime();
    }

    /**
     * 得到month的终止时间点.
     *
     * @param date
     * @return
     */
    public static Date getMonthEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.MILLISECOND, -1);
        return calendar.getTime();
    }

    public static Date addYear(Date date, int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_YEAR, 365 * year);
        return calendar.getTime();
    }

    public static Timestamp strToTimestamp(String dateStr) {
        return Timestamp.valueOf(dateStr);
    }

    public static Timestamp strToTimestamp(Date date) {
        return Timestamp.valueOf(formatTimestamp.format(date));
    }

    public static Timestamp getCurTimestamp() {
        return Timestamp.valueOf(formatTimestamp.format(new Date()));
    }

    /**
     * 取得两个日期之间的日数
     *
     * @return t1到t2间的日数，如果t2 在 t1之后，返回正数，否则返回负数
     */
    public static long daysBetween(Timestamp t1, Timestamp t2) {
        return (t2.getTime() - t1.getTime()) / DAY_MILLI;
    }

    /**
     * 返回java.sql.Timestamp型的SYSDATE
     *
     * @return java.sql.Timestamp型的SYSDATE
     * @history
     * @since 1.0
     */
    public static Timestamp getSysDateTimestamp() {
        return new Timestamp(System.currentTimeMillis());
    }

    /**
     * 利用缺省的Date格式(YYYY/MM/DD)转换String到java.sql.Timestamp
     *
     * @param sDate Date string
     * @return
     * @history
     * @since 1.0
     */
    public static Timestamp toSqlTimestamp(String sDate) {
        if (sDate == null) {
            return null;
        }
        if (sDate.length() != DateUtils.DATE_FORMAT_DATEONLY.length()
                && sDate.length() != DateUtils.DATE_FORMAT_DATETIME.length()) {
            return null;
        }
        return toSqlTimestamp(sDate,
                sDate.length() == DateUtils.DATE_FORMAT_DATEONLY.length()
                        ? DateUtils.DATE_FORMAT_DATEONLY
                        : DateUtils.DATE_FORMAT_DATETIME);

    }

    /**
     * 利用缺省的Date格式(YYYY/MM/DD hh:mm:ss)转化String到java.sql.Timestamp
     *
     * @param sDate Date string
     * @param sFmt  Date format DATE_FORMAT_DATEONLY/DATE_FORMAT_DATETIME
     * @return
     * @history
     * @since 1.0
     */
    public static Timestamp toSqlTimestamp(String sDate, String sFmt) {
        String temp = null;
        if (sDate == null || sFmt == null) {
            return null;
        }
        if (sDate.length() != sFmt.length()) {
            return null;
        }
        if (sFmt.equals(DateUtils.DATE_FORMAT_DATETIME)) {
            temp = sDate.replace('/', '-');
            temp = temp + ".000000000";
        } else if (sFmt.equals(DateUtils.DATE_FORMAT_DATEONLY)) {
            temp = sDate.replace('/', '-');
            temp = temp + " 00:00:00.000000000";
            // }else if( sFmt.equals (DateUtils.DATE_FORMAT_SESSION )){
            // //Format: 200009301230
            // temp =
            // sDate.substring(0,4)+"-"+sDate.substring(4,6)+"-"+sDate.substring(6,8);
            // temp += " " + sDate.substring(8,10) + ":" +
            // sDate.substring(10,12) + ":00.000000000";
        } else {
            return null;
        }
        // java.sql.Timestamp.value() 要求的格式必须为yyyy-mm-dd hh:mm:ss.fffffffff
        return Timestamp.valueOf(temp);
    }

    /**
     * 以YYYY/MM/DD HH24:MI:SS格式返回系统日期时间
     *
     * @return 系统日期时间
     * @history
     * @since 1.0
     */
    public static String getSysDateTimeString() {
        return toString(new Date(System.currentTimeMillis()), DateUtils.sdfDateTime);
    }

    /**
     * 根据指定的Format转化java.util.Date到String
     *
     * @param dt   java.util.Date instance
     * @param sFmt Date format , DATE_FORMAT_DATEONLY or DATE_FORMAT_DATETIME
     * @return
     * @history
     * @since 1.0
     */
    public static String toString(Date dt, String sFmt) {
        if (dt == null || sFmt == null || "".equals(sFmt)) {
            return "";
        }
        return toString(dt, new SimpleDateFormat(sFmt));
    }

    /**
     * 利用指定SimpleDateFormat instance转换java.util.Date到String
     *
     * @param dt        java.util.Date instance
     * @param formatter SimpleDateFormat Instance
     * @return
     * @history
     * @since 1.0
     */
    private static String toString(Date dt, SimpleDateFormat formatter) {
        String sRet = null;

        try {
            sRet = formatter.format(dt).toString();
        } catch (Exception e) {
            logger.error(String.valueOf(e));
            sRet = null;
        }

        return sRet;
    }

    /**
     * 转换java.sql.Timestamp到String，格式为YYYY/MM/DD HH24:MI
     *
     * @param dt java.sql.Timestamp instance
     * @return
     * @history
     * @since 1.0
     */
    public static String toSqlTimestampString2(Timestamp dt) {
        if (dt == null) {
            return null;
        }
        String temp = toSqlTimestampString(dt, DateUtils.DATE_FORMAT_DATETIME);
        return temp.substring(0, 16);
    }

    public static String toString(Timestamp dt) {
        return dt == null ? "" : toSqlTimestampString2(dt);
    }

    /**
     * 根据指定的格式转换java.sql.Timestamp到String
     *
     * @param dt   java.sql.Timestamp instance
     * @param sFmt Date 格式，DATE_FORMAT_DATEONLY/DATE_FORMAT_DATETIME/
     *             DATE_FORMAT_SESSION
     * @return
     * @history
     * @since 1.0
     */
    public static String toSqlTimestampString(Timestamp dt, String sFmt) {
        String temp = null;
        String out = null;
        if (dt == null || sFmt == null) {
            return null;
        }
        temp = dt.toString();
        if (sFmt.equals(DateUtils.DATE_FORMAT_DATETIME) || // "YYYY/MM/DD
                // HH24:MI:SS"
                sFmt.equals(DateUtils.DATE_FORMAT_DATEONLY)) { // YYYY/MM/DD
            temp = temp.substring(0, sFmt.length());
            out = temp.replace('/', '-');
            // }else if( sFmt.equals (DateUtils.DATE_FORMAT_SESSION ) ){
            // //Session
            // out =
            // temp.substring(0,4)+temp.substring(5,7)+temp.substring(8,10);
            // out += temp.substring(12,14) + temp.substring(15,17);
        }
        return out;
    }

    // 得到当前日期的星期
    public static int getWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        int w = cal.get(Calendar.DAY_OF_WEEK);
        return w;
    }

    /**
     * Timestamp 格式转换成yyyy-MM-dd timestampToSql(Timestamp 格式转换成yyyy-MM-dd)
     *
     * @param timestamp 时间
     * @return createTimeStr yyyy-MM-dd 时间
     * @Exception 异常对象
     * @since V1.0
     */
    public static String timestampToStringYMD(Timestamp timestamp) {
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DATE_FORMAT_DATEONLY);
        String createTimeStr = sdf.format(timestamp);
        return createTimeStr;
    }

    /**
     * 判断一个时间是否在某个时间区间内
     *
     * @param now   目标时间
     * @param start 时间区间开始
     * @param end   时间区间结束
     * @param model 区间模式
     * @return 是否在区间内
     */
    public static boolean isBetween(Date now, Date start, Date end, int model) {
        return isBetween(now, start, end, model, LEFT_OPEN_RIGHT_OPEN);
    }

    /**
     * 判断时间是否在制定的时间段之类
     *
     * @param date       需要判断的时间
     * @param start      时间段的起始时间
     * @param end        时间段的截止时间
     * @param interModel 区间的模式
     *
     *                   <pre>
     *                   		取值：
     *                   			LEFT_OPEN_RIGHT_OPEN
     *                   			LEFT_CLOSE_RIGHT_OPEN
     *                   			LEFT_OPEN_RIGHT_CLOSE
     *                   			LEFT_CLOSE_RIGHT_CLOSE
     *                   </pre>
     * @param compModel  比较的模式
     *
     *                   <pre>
     *                   		取值：
     *                   			COMP_MODEL_DATE		只比较日期，不比较时间
     *                   			COMP_MODEL_TIME		只比较时间，不比较日期
     *                   			COMP_MODEL_DATETIME 比较日期，也比较时间
     *                   </pre>
     * @return
     */
    public static boolean isBetween(Date date, Date start, Date end, int interModel, int compModel) {
        if (date == null || start == null || end == null) {
            throw new IllegalArgumentException("日期不能为空");
        }
        SimpleDateFormat format = null;
        switch (compModel) {
            case COMP_MODEL_DATE: {
                format = new SimpleDateFormat("yyyyMMdd");
                break;
            }
            case COMP_MODEL_TIME: {
                format = new SimpleDateFormat("HHmmss");
                break;
            }
            case COMP_MODEL_DATETIME: {
                format = new SimpleDateFormat("yyyyMMddHHmmss");
                break;
            }
            default: {
                throw new IllegalArgumentException(String.format("日期的比较模式[%d]有误", compModel));
            }
        }
        long dateNumber = Long.parseLong(format.format(date));
        long startNumber = Long.parseLong(format.format(start));
        long endNumber = Long.parseLong(format.format(end));
        switch (interModel) {
            case LEFT_OPEN_RIGHT_OPEN: {
                if (dateNumber <= startNumber || dateNumber >= endNumber) {
                    return false;
                } else {
                    return true;
                }
            }
            case LEFT_CLOSE_RIGHT_OPEN: {
                if (dateNumber < startNumber || dateNumber >= endNumber) {
                    return false;
                } else {
                    return true;
                }
            }
            case LEFT_OPEN_RIGHT_CLOSE: {
                if (dateNumber <= startNumber || dateNumber > endNumber) {
                    return false;
                } else {
                    return true;
                }
            }
            case LEFT_CLOSE_RIGHT_CLOSE: {
                if (dateNumber < startNumber || dateNumber > endNumber) {
                    return false;
                } else {
                    return true;
                }
            }
            default: {
                throw new IllegalArgumentException(String.format("日期的区间模式[%d]有误", interModel));
            }
        }
    }

    /**
     * 得到当前周起始时间
     *
     * @param date
     * @return
     */
    public static Date getWeekStart(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.get(Calendar.WEEK_OF_YEAR);
        int firstDay = calendar.getFirstDayOfWeek();
        calendar.set(Calendar.DAY_OF_WEEK, firstDay);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 得到当前周截止时间
     *
     * @param date
     * @return
     */
    public static Date getWeekEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.get(Calendar.WEEK_OF_YEAR);
        int firstDay = calendar.getFirstDayOfWeek();
        calendar.set(Calendar.DAY_OF_WEEK, 8 - firstDay);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 得到当月起始时间
     *
     * @param date
     * @return
     */
    public static Date getMonthStart(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime startDate = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
    LocalDateTime endDate = now.plusMonths(1L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS).plus(-1L, ChronoUnit.MILLIS);
    /**
     * 得到当前年起始时间
     *
     * @param date
     * @return
     */
    public static Date getYearStart(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 得到当前年最后一天
     *
     * @param date
     * @return
     */
    public static Date getYearEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
        calendar.set(Calendar.MONTH, 11);
        calendar.set(Calendar.DAY_OF_MONTH, 31);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 取得月天数
     *
     * @param date
     * @return
     */
    public static int getDayOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    /**
     * 取得月第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDateOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }

    /**
     * 取得月最后一天
     *
     * @param date
     * @return
     */
    public static Date getLastDateOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }

    /**
     * 取得季度第一天
     *
     * @param date
     * @return
     */
    public static Date getSeasonStart(Date date) {
        return getDayStart(getFirstDateOfMonth(getSeasonDate(date)[0]));
    }

    /**
     * 取得季度最后一天
     *
     * @param date
     * @return
     */
    public static Date getSeasonEnd(Date date) {
        return getDayEnd(getLastDateOfMonth(getSeasonDate(date)[2]));
    }

    /**
     * 取得季度月
     *
     * @param date
     * @return
     */
    public static Date[] getSeasonDate(Date date) {
        Date[] season = new Date[3];

        Calendar c = Calendar.getInstance();
        c.setTime(date);

        int nSeason = getSeason(date);
        if (nSeason == 1) {// 第一季度
            c.set(Calendar.MONTH, Calendar.JANUARY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.FEBRUARY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MARCH);
            season[2] = c.getTime();
        } else if (nSeason == 2) {// 第二季度
            c.set(Calendar.MONTH, Calendar.APRIL);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MAY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.JUNE);
            season[2] = c.getTime();
        } else if (nSeason == 3) {// 第三季度
            c.set(Calendar.MONTH, Calendar.JULY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.AUGUST);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.SEPTEMBER);
            season[2] = c.getTime();
        } else if (nSeason == 4) {// 第四季度
            c.set(Calendar.MONTH, Calendar.OCTOBER);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.NOVEMBER);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.DECEMBER);
            season[2] = c.getTime();
        }
        return season;
    }

    /**
     * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
     *
     * @param date
     * @return
     */
    public static int getSeason(Date date) {

        int season = 0;

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH);
        switch (month) {
            case Calendar.JANUARY:
            case Calendar.FEBRUARY:
            case Calendar.MARCH:
                season = 1;
                break;
            case Calendar.APRIL:
            case Calendar.MAY:
            case Calendar.JUNE:
                season = 2;
                break;
            case Calendar.JULY:
            case Calendar.AUGUST:
            case Calendar.SEPTEMBER:
                season = 3;
                break;
            case Calendar.OCTOBER:
            case Calendar.NOVEMBER:
            case Calendar.DECEMBER:
                season = 4;
                break;
            default:
                break;
        }
        return season;
    }

    /**
     * 字符串转date
     *
     * @param dateString
     * @return
     */
    public static Date StringToDate(String dateString) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(dateString);
        } catch (ParseException e) {
            logger.error(String.valueOf(e));
        }
        return date;
    }

    /**
     * 判断输入日期是一个星期中的第几天(星期天为一个星期第一天)
     *
     * @param date
     * @return
     */
    public static int getWeekIndex(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

    /**
     * 当前时间的前几天，并且以例如2013/12/09 00:00:00 形式输出
     */
    public static Date subDays(int days) {
        Date date = addDay(new Date(), -days);
        String dateStr = getReqDate(date);
        Date date1 = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date1 = sdf.parse(dateStr);
        } catch (ParseException e) {
            logger.error(String.valueOf(e));
        }
        return date1;
    }

    /**
     * 判断开始时间和结束时间，是否超出了当前时间的一定的间隔数限制 如：开始时间和结束时间，不能超出距离当前时间90天
     *
     * @param startDate 开始时间
     * @param endDate   结束时间按
     * @param interval  间隔数
     * @param dateUnit  单位(如：月，日),参照Calendar的时间单位
     * @return
     */
    public static boolean isOverIntervalLimit(Date startDate, Date endDate, int interval, int dateUnit) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(dateUnit, interval * (-1));
        Date curDate = getDayStart(cal.getTime());
        if (getDayStart(startDate).compareTo(curDate) < 0 || getDayStart(endDate).compareTo(curDate) < 0) {
            return true;
        }
        return false;
    }

    /**
     * 判断开始时间和结束时间，是否超出了当前时间的一定的间隔数限制, 时间单位默认为天数 如：开始时间和结束时间，不能超出距离当前时间90天
     *
     * @param startDate 开始时间
     * @param endDate   结束时间按
     * @param interval  间隔数
     * @return
     */
    public static boolean isOverIntervalLimit(Date startDate, Date endDate, int interval) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DAY_OF_MONTH, interval * (-1));
        Date curDate = getDayStart(cal.getTime());
        if (getDayStart(startDate).compareTo(curDate) < 0 || getDayStart(endDate).compareTo(curDate) < 0) {
            return true;
        }
        return false;
    }

    /**
     * 判断开始时间和结束时间，是否超出了当前时间的一定的间隔数限制, 时间单位默认为天数 如：开始时间和结束时间，不能超出距离当前时间90天
     *
     * @param startDateStr 开始时间
     * @param endDateStr   结束时间按
     * @param interval     间隔数
     * @return
     */
    public static boolean isOverIntervalLimit(String startDateStr, String endDateStr, int interval) {
        Date startDate = null;
        Date endDate = null;
        try {
            startDate = DateUtils.parseDate(startDateStr, DateUtils.DATE_FORMAT_DATEONLY);
            endDate = DateUtils.parseDate(endDateStr, DateUtils.DATE_FORMAT_DATEONLY);
        } catch (ParseException e) {
            logger.error(String.valueOf(e));
            return false;
        }
        return isOverIntervalLimit(startDate, endDate, interval);
    }

    /**
     * 传入时间字符串及时间格式，返回对应的Date对象
     *
     * @param src     时间字符串
     * @param pattern 时间格式
     * @return Date
     */
    public static Date getDateFromString(String src, String pattern) {
        SimpleDateFormat f = new SimpleDateFormat(pattern);
        try {
            return f.parse(src);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * 取季度
     *
     * @param date
     * @return
     */
    @SuppressWarnings("deprecation")
    public static int getQuarter(Date date) {
        if (date.getMonth() == 0 || date.getMonth() == 1 || date.getMonth() == 2) {
            return 1;
        } else if (date.getMonth() == 3 || date.getMonth() == 4 || date.getMonth() == 5) {
            return 2;
        } else if (date.getMonth() == 6 || date.getMonth() == 7 || date.getMonth() == 8) {
            return 3;
        } else if (date.getMonth() == 9 || date.getMonth() == 10 || date.getMonth() == 11) {
            return 4;
        } else {
            return 0;

        }
    }

    /**
     * 取得通用日期时间格式字符串
     *
     * @param date
     * @return String
     */
    public static String formatDate(Date date) {
        if (date == null) {
            return "";
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(date);
    }

    /**
     * 获取当日的日期格式串
     *
     * @param
     * @return String
     */
    public static String today() {
        return formatDate(new Date(), "yyyy-MM-dd");
    }

    /**
     * 获取当前时间格式串
     *
     * @param
     * @return String
     */
    public static String currentTime() {
        return formatDate(new Date(), "yyyyMMddHHmmssSSS");
    }

    /**
     * 取得指定日期格式的字符串
     *
     * @param date
     * @return String
     */
    public static String formatDate(Date date, String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

    /**
     * 获取昨日的日期格式串
     *
     * @return Date
     */
    public static String getYesterday() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        return formatDate(calendar.getTime(), "yyyy-MM-dd");
    }

    /**
     * 判断当前时间是否在一定的时间范围内
     *
     * @param startTime
     * @return boolean
     */
    public static boolean isInBetweenTimes(String startTime, String endTime) {
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String time = sdf.format(nowTime);
        if (time.compareTo(startTime) >= 0 && time.compareTo(endTime) <= 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 字符转日期
     *
     * @param dateStr
     * @return
     */
    public static Date getDateByStr(String dateStr) {
        SimpleDateFormat formatter = null;
        if (dateStr == null) {
            return null;
        } else if (dateStr.length() == 10) {
            formatter = new SimpleDateFormat("yyyy-MM-dd");
        } else if (dateStr.length() == 16) {
            formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        } else if (dateStr.length() == 19) {
            formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else if (dateStr.length() > 19) {
            dateStr = dateStr.substring(0, 19);
            formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else {
            return null;
        }
        try {
            return formatter.parse(dateStr);
        } catch (ParseException e) {
            logger.error(String.valueOf(e));
            return null;
        }
    }

    /**
     * 根据传入的数字，输出相比现在days天的数据
     *
     * @param days
     * @return Date
     */
    public static Date getDate(int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, days);
        return calendar.getTime();
    }

    /**
     * 日期最大时间
     *
     * @param dt
     * @return
     */
    public static Date getMaxTime(Date dt) {

        Date dt1 = null;
        Calendar ca = Calendar.getInstance();
        ca.setTime(dt);
        ca.add(Calendar.DAY_OF_MONTH, 1);
        dt1 = ca.getTime();
        dt1 = DateUtils.getMinTime(dt1);
        ca.setTime(dt1);
        ca.add(Calendar.SECOND, -1);
        dt1 = ca.getTime();
        return dt1;
    }

    /**
     * 日期最小时间
     *
     * @param dt
     * @return
     */
    public static Date getMinTime(Date dt) {
        Date dt1 = null;
        dt1 = DateUtils.getDateByStr(DateUtils.formatDate(dt, "yyyy-MM-dd"));
        return dt1;
    }

    /**
     * 月的最后一天
     *
     * @param date
     * @return
     */
    @SuppressWarnings("deprecation")
    public static Date getLastDayOfMonth(Date date) {
        Calendar cDay1 = Calendar.getInstance();
        cDay1.setTime(date);
        int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH);
        Date lastDate = cDay1.getTime();
        lastDate.setDate(lastDay);
        return lastDate;
    }

    /**
     * 获取月的某一天
     *
     * @param date      日期
     * @param day       天
     * @param hmsFormat 如：00:00:00 默认:23:59:59
     * @return
     */
    public static Date getNDayOfMonth(Date date, Integer day, String hmsFormat) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, day);
        if (hmsFormat == null || hmsFormat.length() <= 0) {
            hmsFormat = "23:59:59";
        }
        try {
            return LONG_DATE_FORMAT.parse(SHORT_DATE_FORMAT.format(calendar.getTime()) + " " + hmsFormat);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 月的第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDayOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
        return calendar.getTime();
    }

    /**
     * 下月第一天
     *
     * @return
     */
    public static Date getPreviousMonthFirstDay() {
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
        lastDate.add(Calendar.MONTH, +1);// 减一个月，变为下月的1号
        return getMinTime(lastDate.getTime());
    }

    /**
     * 上月最后一天
     *
     * @return
     */
    public static Date getPreviousMonthLastDay() {
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
        lastDate.add(Calendar.DATE, -1);
        return getMinTime(lastDate.getTime());
    }

    /**
     * 两个日期相关天数
     *
     * @param startDate
     * @param endDate
     * @return
     */
    public static long getDateDiff(String startDate, String endDate) {
        long diff = 0;
        try {
            Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(startDate);
            Date date2 = new SimpleDateFormat("yyyy-MM-dd").parse(endDate);

            diff = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) > 0 ? (date1.getTime() - date2.getTime())
                    / (24 * 60 * 60 * 1000)
                    : (date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000);
        } catch (ParseException e) {
        }
        return diff;
    }

    public static long getDateDiff(Date date1, Date date2) {
        if (ValidateUtils.isEmpty(date1) || ValidateUtils.isEmpty(date1)) {
            return 0L;
        }
        long diff = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) > 0 ? (date1.getTime() - date2
                .getTime()) / (24 * 60 * 60 * 1000) : (date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000);
        return diff;
    }

    /*
     * 判断两个时间是不是在一个周中
     */
    public static boolean isSameWeekWithToday(Date date) {

        if (date == null) {
            return false;
        }

        // 0.先把Date类型的对象转换Calendar类型的对象
        Calendar todayCal = Calendar.getInstance();
        Calendar dateCal = Calendar.getInstance();

        todayCal.setTime(new Date());
        dateCal.setTime(date);
        int subYear = todayCal.get(Calendar.YEAR) - dateCal.get(Calendar.YEAR);
        // subYear==0,说明是同一年
        if (subYear == 0) {
            if (todayCal.get(Calendar.WEEK_OF_YEAR) == dateCal.get(Calendar.WEEK_OF_YEAR))
                return true;
        } else if (subYear == 1 && dateCal.get(Calendar.MONTH) == 11 && todayCal.get(Calendar.MONTH) == 0) {
            if (todayCal.get(Calendar.WEEK_OF_YEAR) == dateCal.get(Calendar.WEEK_OF_YEAR))
                return true;
        } else if (subYear == -1 && todayCal.get(Calendar.MONTH) == 11 && dateCal.get(Calendar.MONTH) == 0) {
            if (todayCal.get(Calendar.WEEK_OF_YEAR) == dateCal.get(Calendar.WEEK_OF_YEAR))
                return true;
        }
        return false;
    }

    /**
     * getStrFormTime: <br/>
     *
     * @param form 格式时间
     * @param date 时间
     * @return
     */
    public static String getStrFormTime(String form, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(form);
        return sdf.format(date);
    }

    /**
     * 获取几天内日期 return 2014-5-4、2014-5-3
     */
    public static List<String> getLastDays(int countDay) {
        List<String> listDate = new ArrayList<String>();
        for (int i = 0; i < countDay; i++) {
            listDate.add(DateUtils.getReqDateyyyyMMdd(DateUtils.getDate(-i)));
        }
        return listDate;
    }

    /**
     * 对时间进行格式化
     *
     * @param date
     * @return
     */
    public static Date dateFormat(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date value = new Date();

        try {
            value = sdf.parse(sdf.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return value;

    }

    /**
     * 获得当前时间对应的指定格式
     *
     * @param pattern
     * @return
     */
    public static String currentFormatDate(String pattern) {
        simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date());
    }

    /**
     * 获取指定年月的最后一天
     *
     * @param year
     * @param month
     * @return
     */
    public static Integer getLastDayOfMonth1(Integer year, Integer month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DATE);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(cal.getTime());
        String dayS = format.substring(format.length() - 2);
        Integer day = Integer.valueOf(dayS);
        return day;
    }

    /**
     * 取季度
     *
     * @param dateS
     * @return
     */
    public static Integer getQuarterExt(String dateS) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = formatter.parse(dateS);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (date.getMonth() == 0 || date.getMonth() == 1 || date.getMonth() == 2) {
            return 1;
        } else if (date.getMonth() == 3 || date.getMonth() == 4 || date.getMonth() == 5) {
            return 2;
        } else if (date.getMonth() == 6 || date.getMonth() == 7 || date.getMonth() == 8) {
            return 3;
        } else if (date.getMonth() == 9 || date.getMonth() == 10 || date.getMonth() == 11) {
            return 4;
        } else {
            return 0;
        }
    }

    /**
     * 获取指定日期到当前时间经过了多天
     *
     * @param dstr
     * @return
     */
    public static Integer getDateToDay(Date dstr) {
        long s1 = dstr.getTime();//将时间转为毫秒
        long s2 = System.currentTimeMillis();//得到当前的毫秒
        long day = (s2 - s1) / 1000 / 60 / 60 / 24;
        Integer b = (int) day;
        /*System.out.println("距现在已有" + b + "天，你得抓紧时间学习了");*/
        return b;
    }

    /**
     * 获取时间所在季度的最后一个月
     *
     * @param date
     * @return
     */
    public static Date getQuarterEndTime(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int currentMonth = c.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 3) {
                c.set(Calendar.MONTH, 2);
                c.set(Calendar.DATE, 31);
            } else if (currentMonth >= 4 && currentMonth <= 6) {
                c.set(Calendar.MONTH, 5);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 7 && currentMonth <= 9) {
                c.set(Calendar.MONTH, 8);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 10 && currentMonth <= 12) {
                c.set(Calendar.MONTH, 11);
                c.set(Calendar.DATE, 31);
            }
            now = LONG_DATE_FORMAT.parse(SHORT_DATE_FORMAT.format(c.getTime()) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * @param date
     * @param day
     * @param hmsFormat
     * @return
     */
    public static Date getQuarterEndTime(Date date, Integer day, String hmsFormat) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int currentMonth = c.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 3) {
                c.set(Calendar.MONTH, 2);
                c.set(Calendar.DATE, day);
            } else if (currentMonth >= 4 && currentMonth <= 6) {
                c.set(Calendar.MONTH, 5);
                c.set(Calendar.DATE, day);
            } else if (currentMonth >= 7 && currentMonth <= 9) {
                c.set(Calendar.MONTH, 8);
                c.set(Calendar.DATE, day);
            } else if (currentMonth >= 10 && currentMonth <= 12) {
                c.set(Calendar.MONTH, 11);
                c.set(Calendar.DATE, day);
            }
            if (hmsFormat == null || hmsFormat.length() <= 0) {
                hmsFormat = "23:59:59";
            }
            now = LONG_DATE_FORMAT.parse(SHORT_DATE_FORMAT.format(c.getTime()) + " " + hmsFormat);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获取年的结束时间
     *
     * @return
     */
    public static Date getCurrentYearEndTime(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        Date now = null;
        try {
            c.set(Calendar.MONTH, 11);
            c.set(Calendar.DATE, 31);
            now = LONG_DATE_FORMAT.parse(SHORT_DATE_FORMAT.format(c.getTime()) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获取指定时间年的结束时间
     *
     * @param date      日期
     * @param day       天
     * @param hmsFormat 如00:00:00 默认是23:59:59
     * @return
     */
    public static Date getCurrentYearEndTime(Date date, Integer day, String hmsFormat) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        Date now = null;
        try {
            c.set(Calendar.MONTH, 11);
            c.set(Calendar.DATE, day);
            if (hmsFormat == null || hmsFormat.length() <= 0) {
                hmsFormat = "23:59:59";
            }
            now = LONG_DATE_FORMAT.parse(SHORT_DATE_FORMAT.format(c.getTime()) + " " + hmsFormat);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }






	public static String getFirstDayOfMonth(String datestr){
		if (StringUtils.isBlank(datestr)) return  null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = strToDateNotDD(datestr);
		LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());;
		LocalDateTime endOfDay = localDateTime.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
		Date dates = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
		return sdf.format(dates);
	}
    /**
     * 获取当前月第一天
     * @param month
     * @return
     */
    public static String getFirstDayOfMonth(int month) {
        Calendar calendar = Calendar.getInstance();
        // 设置月份
        calendar.set(Calendar.MONTH, month - 1);
        // 获取某月最小天数
        int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
        // 设置日历中月份的最小天数
        calendar.set(Calendar.DAY_OF_MONTH, firstDay);
        // 格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDays = sdf.format(calendar.getTime())+" 00:00:00";
        return firstDays;
    }

	public static String getLastDayOfMonth(String datestr){
		if (StringUtils.isBlank(datestr)) return  null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = strToDateNotDD(datestr);
		LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());;
		LocalDateTime endOfDay = localDateTime.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
		Date dates = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
		return sdf.format(dates);
	}
    public static String getLastDayOfMonth(int month) {
        Calendar calendar = Calendar.getInstance();
        // 设置月份
        calendar.set(Calendar.MONTH, month - 1);
        // 获取某月最大天数
        int lastDay=0;
        //2月的平年瑞年天数
        if(month==2) {
            lastDay = calendar.getLeastMaximum(Calendar.DAY_OF_MONTH);
        }else {
            lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        }
        // 设置日历中月份的最大天数
        calendar.set(Calendar.DAY_OF_MONTH, lastDay);
        // 格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String lastDays = sdf.format(calendar.getTime())+" 23:59:59";
        return lastDays;
    }
	/**
	 * 将短时间格式字符串转换为时间 yyyy-MM( 2017-02)
	 * @param strDate
	 * @return
	 */
	public static Date strToDateNotDD(String strDate) {
		if (StringUtils.isBlank(strDate)) return null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
		ParsePosition pos = new ParsePosition(0);
		Date strtodate = formatter.parse(strDate, pos);
		return strtodate;
	}
    /**
     * 将短时间格式字符串转换为时间 yyyy-MM-dd( 2017-02)
     * @param strDate
     * @return
     */
    public static Date strToDate(String strDate) {
        if (StringUtils.isBlank(strDate)) return null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }
	/**
	 * 获得指定日期的前一天
	 * @param specifiedDay
	 * @return
	 * @throws Exception
	 */
	public static String getSpecifiedDayBefore(String specifiedDay){
		Calendar c = Calendar.getInstance();
		Date date=null;
		try {
			date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day=c.get(Calendar.DATE);
		c.set(Calendar.DATE,day-1);

		String dayBefore=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
		return dayBefore;
	}

    /**
     * 字符串yyyy/MM/dd转Date
     * @param day
     * @return
     * @throws ParseException
     */
    public static Date timeFormat(String day) throws ParseException {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//定义一个formate
        Date date = simpleDateFormat.parse(day);//将formate型转化成Date数据类型
        return date;

    }

    /**
     * 获取YYYY格式
     *
     * @return
     */
    public static String getYear(Date date) {
        return sdfYear.format(date);
    }
    /**
     * Date转String
     *
     */
    public static String dateToString(Date date) {
        SimpleDateFormat ft = new SimpleDateFormat(DATE_FORMAT_DATETIME);
        String time = ft.format(date);
        return time;
    }


    /**
     * 获取YYYY格式
     *
     * @return
     */
    public static String getMonth(Date date) {
        return sdfMonth.format(date);
    }

    /**
     * 获取指定年指定季度的开始时间结束时间
     * @param year 指定
     * @param quarter 指定季度
     * @return MAP（开始时间，结束时间）
     */
    public static Map queryTheQuarterStartEnd(String year, String quarter){
        String time ="";
        if (quarter.equals("1")){
            time = year+"-02-01 00:00:00";
        }
        if (quarter.equals("2")){
            time = year+"-05-01 00:00:00";
        }
        if (quarter.equals("3")){
            time = year+"-08-01 00:00:00";
        }
        if (quarter.equals("4")){
            time = year+"-12-01 00:00:00";
        }
        String start = formatDate(getSeasonStart(StringToDate(time)));
        String end = formatDate(getSeasonEnd(getMaxTime(StringToDate(time))));
        Map<String ,String> mapnew = new HashMap<>();
        mapnew.put("start",start);
        mapnew.put("end",end);
        return mapnew;
    }


    /**
     * 解析对象到日期
     */
    public static Date objectToDate(Object o) {
        if (o == null) {
            return null;
        }
        if (o instanceof Date) {
            return (Date) o;
        }
        if (o instanceof java.sql.Date) {
            return (Date) o;
        }
        if (o instanceof String) {
            // yyyy-MM-dd HH:mm:ss  /
            String d=(String) o;
            StringBuilder format=new StringBuilder("yyyy");
            if (d.charAt(4)=='-') {
                format.append("-MM-dd");
            }else if(d.charAt(4)=='/') {
                format.append("/MM/dd");
            }else if (d.charAt(4)=='_'){
                format.append("_MM_dd");
            }else {
                format.append("MMdd");
            }
            if (d.length()<format.length()) {
                return null;
            }else if (d.length()==format.length()) {
                return parsingTheDate(d, format.toString());
            }
            if (d.charAt(format.length())==' ') {
                format.append(' ');
            }
            if (d.charAt(format.length()+2)==':') {
                format.append("HH:mm:ss");
            }else if (d.charAt(format.length()+2)=='/') {
                format.append("HH/mm/ss");
            }else {
                format.append("HHmmss");
            }
            if (d.length()<format.length()) {
                return null;
            }
            if (d.length()==format.length()) {
                return parsingTheDate(d,format.toString());
            }
            if (d.charAt(format.length())=='.'&&d.length()==(format.length()+4)) {
                format.append(".SSS");
            }else if(d.length()==(format.length()+3)){
                format.append("SSS");
            }else {
                d=d.substring(0, format.length());
            }
            return parsingTheDate(d, format.toString());
        }
        if (o instanceof Long) {
            long l=(long) o;
            if (l < 10000000000l) {
                return new Date(l*1000);
            }
            return new Date(l);
        }
        if (o instanceof Integer) {
            long l=(int)o*1000;
            return new Date(l);
        }
        return null;
    }
    /**
     * 解析字符串日期,不报错  异常返回null
     * @param d
     * @param format
     * @return
     * @author lsg
     * @created 2018-11-27 下午4:30:35
     */
    public static Date parsingTheDate(String d,String format) {
        try {
            return new SimpleDateFormat(format).parse(d);
        } catch (ParseException e) {
            return null;
        }
    }
    // 获得某天最大时间 2017-10-15 23:59:59
    public static Date getEndOfDay(Date date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());;
        LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
        return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
    }

    /**
     * 导入excel转date
     * @param dataStr
     * @return date
     */
    public static Date excelImportString(String dataStr) throws ParseException {
        if (dataStr != null && !dataStr.equals("")){
            SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.US);
            try {
                Date parse = sdf.parse(dataStr);
                return parse;
            }catch (Exception e){
                return null;
            }
        }else {
            return null;
        }

    }
    /**
     * 判断时间是否在时间段内
     *
     * @param nowTime
     * @param beginTime
     * @param endTime
     * @return
     */
    public static boolean belongCalendar(Date nowTime, Date beginTime,
                                         Date endTime) {
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.equals(begin)){
            return true;
        }
        if (date.equals(end)){
            return true;
        }

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取昨日的日期格式串
     *
     * @return Date
     */
    public static String forHalfAYear(Integer day) {
        if ( day == null ){
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -day);
        return formatDate(calendar.getTime(), DATE_FORMAT_DATETIME);
    }

    /*public static void main(String[] args) throws ParseException {
*//*		Date date3 = DateUtils.addMinutes(new Date(), 5);
		System.out.println(new Date().after(DateUtils.addMinute(new Date(), -10)));
		Date date1 = DateUtils.addMinutes(new Date(), -1);
		Date date2 = DateUtils.addMinutes(date1, 5);
		System.out.println(date1);
		System.out.println(date2);
		System.out.println(DateUtils.isBetween(new Date(), date1, date2, DateUtils.COMP_MODEL_TIME));
*//*
//		Calendar cal = Calendar.getInstance();
//        //获取当前年
//        Integer year = cal.get(Calendar.YEAR);
//        //获取当前月
//        Integer month = cal.get(Calendar.MONTH )+1;
//        //获取当前号
//        Integer day=cal.get(Calendar.DATE);
//		System.out.println(year-1);
//		System.out.println(year-5);
//		System.out.println();

//        try {
//            Date date1=LONG_DATE_FORMAT.parse("2019-12-31 23:59:59");
//            Date date2=LONG_DATE_FORMAT.parse("2019-12-31 23:59:59");
//            System.out.println(date1.equals(date2));
//            System.out.println(date1.compareTo(date2));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }

//        Calendar c = Calendar.getInstance();
//        c.setTime(new Date());
//        System.out.println(c.get(Calendar.DATE));
//        System.out.println(LONG_DATE_FORMAT.format(c.getTime()));
//
//		System.out.println(LONG_DATE_FORMAT.format(getQuarterEndTime(new Date())));
*//*        System.out.println(LONG_DATE_FORMAT.format(getCurrentYearEndTime(new Date(),32,"00:00:00")));
        System.out.println(LONG_DATE_FORMAT.format(getQuarterEndTime(new Date(),31,"00:00:00")));
        System.out.println(LONG_DATE_FORMAT.format(getNDayOfMonth(new Date(),15,"00:00:00")));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");*//*
        *//**
         * 获取季度的最后一天getSeasonEnd
         * getFirstDayOfMonth月的第一天
         *//*
        //获取季度的最后一天getSeasonEnd
	*//*	System.out.println(getSeasonEnd(new Date()));
		System.out.println(getFirstDayOfMonth(getSeasonEnd(new Date())));
		System.out.println(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));

		Integer a=1;
		if(a>Calendar.getInstance().get(Calendar.DAY_OF_MONTH)){

		}
		System.out.println(addDay(getFirstDayOfMonth(getSeasonEnd(new Date())), 2 - 1));*//*
        String a = "入职时间" + "" + "入职可用" + "1";
        String startTime = "2019-06-25 10:42:30.723";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  //格式转换工具
        Date date = sdf.parse(startTime);
        String format = DateUtils.SHORT_DATE_FORMAT.format(date);
        Date date1 = StringToDate(format);
        Date date2 = StringToDate(today());
        System.out.println(date1);
        System.out.println(date2);
        if (date1.after(date2)) {
            System.out.println("未到积分可用时间");
        } else {
            System.out.println("到积分可用时间了");
        }
        System.out.println(addDay(new Date(), -1));
    }*/
    /*public static void main(String[] args) throws ParseException {
        System.out.println(DateUtils.getReqDates());
        System.out.println(timeFormat(DateUtils.getReqDates()));
    }*/

    /**
     * 获取指定年指定季度的开始时间结束时间
     * @param year 指定
     * @param quarter 指定季度
     * @return MAP（开始时间，结束时间）
     */
    public static List<Map> queryAllMonthsOfTheQuarter(String year, String quarter){
        Date[] season = new Date[3];
        String time ="";
        if (quarter.equals("1")){
            time = year+"-02-01";
        }
        if (quarter.equals("2")){
            time = year+"-05-01";
        }
        if (quarter.equals("3")){
            time = year+"-08-01";
        }
        if (quarter.equals("4")){
            time = year+"-12-01";
        }
        Date seasonStart = getSeasonStart(StringToDate(time));
        Calendar c = Calendar.getInstance();
        c.setTime(seasonStart);
        List<Map> list = new ArrayList<>();
        int nSeason = getSeason(seasonStart);
        if (nSeason == 1) {// 第一季度
            c.set(Calendar.MONTH, Calendar.JANUARY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.FEBRUARY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MARCH);
            season[2] = c.getTime();
        } else if (nSeason == 2) {// 第二季度
            c.set(Calendar.MONTH, Calendar.APRIL);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MAY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.JUNE);
            season[2] = c.getTime();
        } else if (nSeason == 3) {// 第三季度
            c.set(Calendar.MONTH, Calendar.JULY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.AUGUST);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.SEPTEMBER);
            season[2] = c.getTime();
        } else if (nSeason == 4) {// 第四季度
            c.set(Calendar.MONTH, Calendar.OCTOBER);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.NOVEMBER);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.DECEMBER);
            season[2] = c.getTime();
        }
        for (Date date : season) {
            Map map = new HashMap();
            c.setTime(date);
            int month = c.get(Calendar.MONTH);
            map.put("month",month + 1);
            map.put("startTime", getFirstDateOfMonth(date));
            map.put("endTime", getLastDateOfMonth(date));
            list.add(map);
        }
        return list;
    }

    /**
     * 给定年月获取每周的开始和结束时间
     * @param year
     * @param month
     * @return
     */
    public static Map<Integer, WeekData> weeks(int year, int month){
        LocalDate start = LocalDate.now().withYear(year).withMonth(month).with(TemporalAdjusters.firstDayOfMonth());
        LocalDate end = LocalDate.now().withYear(year).withMonth(month).with(TemporalAdjusters.lastDayOfMonth());
        Map<Integer, WeekData> map = Stream.iterate(start, localDate -> localDate.plusDays(1))
                .limit(ChronoUnit.DAYS.between(start, end)+1)
                .collect(Collectors.groupingBy(localDate -> localDate.get(WeekFields.of(DayOfWeek.MONDAY, 1).weekOfMonth()),
                        Collectors.collectingAndThen(Collectors.toList(), WeekData::new)));
        return  map;
    }

    /**
     * LocalDate转Date
     * @param localDate
     * @return
     */
    public static Date localDate2Date(LocalDate localDate) {
        if(null == localDate) {
            return null;
        }
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
        return dateFormat(Date.from(zonedDateTime.toInstant()));
    }

    /**
     * Date转LocalDate
     * @param date
     */
    public static LocalDate date2LocalDate(Date date) {
        if(null == date) {
            return null;
        }
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }

    /**
     * 指定年月的开始时间
     * @param year
     * @param month
     * @return
     */
    public static LocalDate getBeginTimeFromYearAndMonth(int year, int month) {
        YearMonth yearMonth = YearMonth.of(year, month);
        LocalDate localDate = yearMonth.atDay(1);
        LocalDateTime startOfDay = localDate.atStartOfDay();
        ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai"));

        return Date.from(zonedDateTime.toInstant()).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }

    /**
     * 指定时间的结束时间
     * @param year
     * @param month
     * @return
     */
    public static LocalDate getEndTimeFromYearAndMonth(int year, int month) {
        YearMonth yearMonth = YearMonth.of(year, month);
        LocalDate endOfMonth = yearMonth.atEndOfMonth();
        LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);
        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
        LocalDate localDate = Date.from(zonedDateTime.toInstant()).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        return localDate;
    }

    /**
     * 指定年获取年度每月的开始结束时间
     *
     * @param year 年
     * @return
     */
    public static Map<Integer, WeekData> getByTheMonthBeginningAndEndTime(Integer year){
        Map<Integer, WeekData> map = new HashMap<>();
        for (int i = 1; i <= 12; i++) {
            WeekData weekData = new WeekData();
            weekData.setStart(getBeginTimeFromYearAndMonth(year,i));
            weekData.setEnd(getEndTimeFromYearAndMonth(year,i));
            map.put(i,weekData);
        }
        return map;
    }


    /**
     * 非财年统计，3天分一组
     *
     * @param dateTime 开始时间
     * @return
     */
    public static List<Map> listDays(Date dateTime) {
        LocalDate firstDay = date2LocalDate(getFirstDateOfMonth(dateTime));
        LocalDate lastDay = date2LocalDate(getLastDateOfMonth(dateTime));
        List<Map> maps = new ArrayList<>();
        LocalDate date = firstDay;
        List<LocalDate> dates = new ArrayList<>();
        for (; ; ) {
            if (date.isAfter(lastDay)) {
                /*dates.add(lastDay);*/
                break;
            }
            dates.add(date);
            date = date.plusDays(3L);
        }
        processingTimeGrouping(maps,dates);
        return maps;
    }

    /**
     * 财年统计，3天分一组
     *
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    public static List<Map> listDays(Date startTime, Date endTime) {
        LocalDate firstDay = date2LocalDate(startTime);
        LocalDate lastDay = date2LocalDate(endTime);
        List<Map> maps = new ArrayList<>();
        LocalDate date = firstDay;
        List<LocalDate> dates = new ArrayList<>();
        for (; ; ) {
            if (date.isAfter(lastDay)) {
                dates.add(lastDay);
                break;
            }
            dates.add(date);
            date = date.plusDays(3L);
        }
        for (LocalDate localDate : dates) {
            Map map = new HashMap();
            map.put("sta",getMinTime(localDate2Date(localDate)));
            map.put("end",getMaxTime(addDay(localDate2Date(localDate),2)));
            maps.add(map);
        }
        return maps;
    }

    /**
     * 处理时间
     * @param maps
     * @param dates
     */
    public static void processingTimeGrouping(List<Map> maps, List<LocalDate> dates){
        for (LocalDate localDate : dates) {

            Map map = new HashMap();
            map.put("sta",getMinTime(localDate2Date(localDate)));
            if (!isSameDate(getMinTime(localDate2Date(localDate)),getMaxTime(addDay(localDate2Date(localDate), 2)))){
                map.put("end",getMaxTime(getLastDayOfMonth(localDate2Date(localDate))));
                maps.add(map);
                break;
            }
            map.put("end",getMaxTime(addDay(localDate2Date(localDate), 2)));
            maps.add(map);
        }
    }

    /**
     *  判断时间2是否跟时间一同意年月
     *
     * @param date1 时间1
     * @param date2 时间2
     * @return isSameMonth
     */
    public static boolean isSameDate(Date date1, Date date2) {
        try {
            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(date1);

            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(date2);

            boolean isSameYear = cal1.get(Calendar.YEAR) == cal2
                    .get(Calendar.YEAR);
            boolean isSameMonth = isSameYear
                    && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
            return isSameMonth;
        } catch (Exception e) {

        }
        return false;


    }

    /**
     * 传入指定时间范围，获取该范围内的月份
     * @param minDate
     * @param maxDate
     * @return
     * @throws Exception
     */
    public static List<String> getMonthBetween(Date minDate, Date maxDate){
        ArrayList<String> result = new ArrayList<String>();

        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();

        min.setTime(minDate);
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);

        max.setTime(maxDate);
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);

        Calendar curr = min;
        while (curr.before(max)) {
            result.add(SHORT_DATE_FORMAT.format(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }

        return result;
    }

    /**
     * 传入指定时间范围，获取该范围内的所有年
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public static List<Integer> getYearBetween(Date dateStart, Date dateEnd){
        List<Integer> list = new ArrayList<>();
        Date date = dateStart;
        Calendar cd = Calendar.getInstance();
        while (date.getYear() <= dateEnd.getYear()) {
            cd.setTime(date);
            list.add(cd.get(Calendar.YEAR));
            cd.add(Calendar.YEAR, 1);
            date = cd.getTime();
        }
        return list;
    }

    /**
     * 计算2个日期之间相差的  相差多少年月日
     * 比如：2011-02-02 到  2017-03-02 相差 6年，1个月，0天
     * @param fromDate
     * @param toDate
     * @return
     */
    public static DayCompare dayComparePrecise(Date fromDate, Date toDate){
        Calendar  from  =  Calendar.getInstance();
        from.setTime(fromDate);
        Calendar  to  =  Calendar.getInstance();
        to.setTime(toDate);

        int fromYear = from.get(Calendar.YEAR);
        int fromMonth = from.get(Calendar.MONTH);
        int fromDay = from.get(Calendar.DAY_OF_MONTH);

        int toYear = to.get(Calendar.YEAR);
        int toMonth = to.get(Calendar.MONTH);
        int toDay = to.get(Calendar.DAY_OF_MONTH);
        int year = toYear  -  fromYear;
        int month = toMonth  - fromMonth;
        int day = toDay  - fromDay;
        return null;
    }

    /**
     *
     * @param nowTime   当前时间
     * @param startTime	开始时间
     * @param endTime   结束时间
     * @return
     * @author sunran   判断当前时间在时间区间内
     */
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) throws ParseException {

        /*Date date = parseDate(getYesterday()+" 00:00:03", "yyyy-MM-dd HH:mm:ss");
        Date date2 = parseDate(getYesterday()+" 04:00", "yyyy-MM-dd HH:mm");
        if(date.after(date2)){

        }
        System.out.println(date);

        Calendar calX = Calendar.getInstance();
        //获取当前年
        Integer year = calX.get(Calendar.YEAR);
        //获取当前月
        Integer month = calX.get(Calendar.MONTH) + 1;
        Integer lastDay= getLastDayOfMonth1(year, month);
        System.out.println(year+"-"+month+"-"+1+" 23:59:59");*/
        List<Map> maps = listDays(new Date());
        Date endOfDay = DateUtils.getEndOfDay(StringToDate("2049-1-1"));
        System.out.println(endOfDay);


    }
}

